package com.剑指offer;

public class _57二叉树的下一个结点
{
    public static void main(String[] args)
    {

    }

    public TreeLinkNode GetNext(TreeLinkNode pNode)
    {
        TreeLinkNode node = pNode;
        if (node == null)
        {
            return null;
        }
        if (node.right != null)
        {
            node = node.right;
            while (node.left != null)
            {
                node = node.left;
            }
            return node;
        }
        while (node.next != null)
        {
            if (node.next.left == node)
            {
                return node.next;
            }
            node = node.next;
        }
        return null;
    }
}
